package com.giaothong.model.entity;

import org.json.JSONObject;

import com.giaothong.utils.JSONUtil;
import com.google.android.maps.GeoPoint;

public class LocationStatus {

	public static final int CONG_TRINH_GIAO_THONG = 0;
	public static final int MAT_TIN_HIEU_GIAO_THONG = 1;
	public static final int CO_CANH_SAT = 2;
	public static final int TAI_NAN_GIAO_THONG = 3;
	public static final int KET_CUNG = 4;
	public static final int DI_CHUYEN_KHO_KHAN = 5;
	public static final int DI_CHUYEN_CHAM = 6;
	public static final int DI_CHUYEN_ON_DINH = 7;
	public static final int THONG_THOANG = 8;

	private String locationId;
	private String infoName;
	private String address;
	private GeoPoint geoPoint;
	private int status;
	private String userPostId;

	/**
	 * setter & getter
	 */
	public void setGeoPoint(GeoPoint geoPoint) {
		this.geoPoint = geoPoint;
	}

	public void setInfoName(String infoName) {
		this.infoName = infoName;
	}

	public void setLocationId(String locationId) {
		this.locationId = locationId;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public void setUserPostId(String userPostId) {
		this.userPostId = userPostId;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getAddress() {
		return address;
	}

	public GeoPoint getGeoPoint() {
		return geoPoint;
	}

	public String getInfoName() {
		return infoName;
	}

	public String getLocationId() {
		return locationId;
	}

	public int getStatus() {
		return status;
	}

	public String getUserPostId() {
		return userPostId;
	}

	/**
	 * value parse Json
	 */
	public static final String LOCATION_ID = "id";
	public static final String INFO_NAME = "infomation_name";
	public static final String LAT = "latitude";
	public static final String LONG = "longitude";
	public static final String STATUS = "status";
	public static final String USER_ID = "user_id";
	public static final String ADDRESS = "address";

	/**
	 * contructor
	 */
	public LocationStatus() {
		setDefautValue();
	}

	public LocationStatus(JSONObject jsonObject) {
		setDefautValue();
		if (jsonObject == null)
			return;
		this.infoName = JSONUtil.stringTryGetValue(jsonObject, INFO_NAME);
		this.locationId = JSONUtil.stringTryGetValue(jsonObject, LOCATION_ID);
		this.status = JSONUtil.intTryGetValue(jsonObject, STATUS);
		this.userPostId = JSONUtil.stringTryGetValue(jsonObject, USER_ID);
		this.geoPoint = new GeoPoint(Integer.parseInt(JSONUtil.stringTryGetValue(jsonObject, LAT)), Integer.parseInt(JSONUtil.stringTryGetValue(jsonObject, LONG)));
		this.address = JSONUtil.stringTryGetValue(jsonObject, ADDRESS);
	}

	private void setDefautValue() {
		this.geoPoint = new GeoPoint(0, 0);
		this.infoName = "";
		this.locationId = "";
		this.status = -1;
		this.userPostId = "";
		this.address = "";
	}

}
